/**
 * 
 */
package pacMan;

import java.awt.Graphics2D;

/**
 * Class: BasicDrawableObject
 * 
 * Base class for everything that will be drawn on-screen. Contains a Coordinate location,
 * draw method, resize method, and attributes that determine if the object is visible or a
 * placeholder for a derived class set of attributes.
 * 
 * @author 		Tomas Rivera
 * @version 	$Id$
 *
 */
public abstract class BasicDrawableObject {
	
	//////////////////////////////////////////////////////////
	// Constructor methods
	//////////////////////////////////////////////////////////
	
	/**
	 * Creates a BasicDrawable object that can be drawn on-screen.
	 * 
	 * @param c
	 * @param w
	 */
	public BasicDrawableObject(Coordinate c, WindowParameters w) {
		objectLocation = c;
		windowParams = w;
		obstacle = false;
	}
	
	//////////////////////////////////////////////////////////
	// Abstract methods
	//////////////////////////////////////////////////////////
	
	/**
	 * Defines the object to be drawn using x,y values contained
	 * in Coordinate object.
	 * 
	 * @param g2d
	 */
	public abstract void drawObject(Graphics2D g2d);
	
	/**
	 * Method for resizing the object based on updated values
	 * in WindowParameters object.
	 * 
	 */
	public abstract void resizeObject();
	
	//////////////////////////////////////////////////////////
	// Public methods
	//////////////////////////////////////////////////////////
	
	/**
	 * Get a reference to the Coordinate object.
	 * 
	 * @return the objectLocation
	 */
	public Coordinate getObjectLocation() {
		return objectLocation;
	}
	
	/**
	 * Get the game board tile row index that the object is within.
	 *
	 * @return
	 */
	public int getGridLocationX() {
		return (objectLocation.getX() - (objectLocation.getX() % windowParams.getPixelScale()) - windowParams.getPixelOffsetX()) / windowParams.getPixelScale();
	}
	
	/**
	 * Get the game board tile column index that the object is within.
	 * 
	 * @return
	 */
	public int getGridLocationY() {
		return (objectLocation.getY() - (objectLocation.getY() % windowParams.getPixelScale()) - windowParams.getPixelOffsetY()) / windowParams.getPixelScale();
	}
	
	/**
	 * Get the pixel X coordinate of the object.
	 * 
	 * @return
	 */
	public int getPixelXLocation() { return this.getObjectLocation().getX(); }
	
	/**
	 * Get the pixel Y coordinate of the object.
	 * 
	 * @return
	 */
	public int getPixelYLocation() { return this.getObjectLocation().getY(); }
	
	/**
	 * Checks if the object is centered horizontally within a box with height and width
	 * equal to the pixel scale value defined in WindowParameters object.
	 * 
	 * @return 
	 */
	public boolean isCenteredHorizontally() {
		return (getObjectLocation().getX() % getWindowParams().getPixelScale() == 0);
	}
	
	/**
	 * Checks if the object is centered vertically within a box with height and width
	 * equal to the pixel scale value defined in WindowParameters object.
	 * 
	 * @return
	 */
	public boolean isCenteredVertically() {
		return (getObjectLocation().getY() % getWindowParams().getPixelScale() == 0);
	}
	
	/**
	 * Get a reference to the WindowParameters object.
	 * @return
	 */
	public WindowParameters getWindowParams() {
		return windowParams;
	}
	
	/**
	 * Checks if the object is flagged as an obstacle to moving objects.
	 * 
	 * @return obstacle
	 */
	public boolean isObstacle() {
		return obstacle;
	}
	
	/**
	 * Marks object as one that another movable object is not allowed
	 * to pass through or occupy the same space as.
	 * 
	 * @param obstacle
	 */
	protected void markObstacle(boolean obstacle) {
		this.obstacle = obstacle;
	}
	
	/**
	 * Checks if the object is a marker for part of a game board "tunnel".
	 * 
	 * @return tunnelPlaceHolder
	 */
	public boolean isTunnelPlaceHolder() { return tunnelPlaceHolder; }
	

	//////////////////////////////////////////////////////////
	// Private member variables
	//////////////////////////////////////////////////////////
	
	private Coordinate objectLocation;
	private WindowParameters windowParams;
	private boolean obstacle;
	protected boolean tunnelPlaceHolder;

}
